﻿using Common.ExceptionHandlers;
using Microsoft.EntityFrameworkCore;

namespace Common.Helpers;

public static class ThrowHelper
{
    public static T ThrowIfNull<T>(T value, string paramName) where T : class
    {
        if (value == null)
        {
            throw new ArgumentNullException(paramName);
        }
        return value;
    }

    public static void ThrowIfNotFound(bool condition, string message = "数据不存在！")
    {
        if (condition) throw new NotFoundException(message);
    }

    public static void ThrowConcurrencyException(string message)
    {
        throw new DbUpdateConcurrencyException(message);
    }

    public static void ThrowCustomException(string message)
    {
        throw new Exception(message);
    }
}
